package com.xiaohudie.SSGworket;

import lombok.SneakyThrows;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author xiao hu die
 * @Date 2022/3/27 19:02
 * @Version 1.0
 */
public class TcpTest04 {
    @SneakyThrows
    public static void main(String[] args) {
        ServerSocket serverSocket = new ServerSocket(8899);
        Socket accept = serverSocket.accept();
        InputStream inputStream = accept.getInputStream();
        FileOutputStream fileOutputStream = new FileOutputStream(new File("D:\\java图片代码\\1919.txt"));
        byte[] bytes =new byte[1024];
        int len;
        while ((len=inputStream.read(bytes))!=-1){
            fileOutputStream.write(bytes,0,len);
            System.out.println("接收文件成功");
        }
        OutputStream outputStream = accept.getOutputStream();
        outputStream.write(("接收成功").getBytes());
        serverSocket.close();
        inputStream.close();
        fileOutputStream.close();
        outputStream.close();
        accept.close();

    }
}
